/**
* @ClassName: Chinese2Pinyin
* @Description: 
* @author YuYang
* @date 2013-6-24 下午2:49:32
*/
package com.yang.test;

import com.demodis.util.Utils;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class Chinese2Pinyin {

	public static void main(String[] args) {  
		String abbr = Chinese2Pinyin.getChineseAbbr("黄健");
		System.out.println(abbr);
    } 
	
	public static String getChineseAbbr(String str) {
		HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();  
        outputFormat.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);  
        outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);  
        StringBuffer abbr = new StringBuffer();
        try {  
            for (int i = 0; i < str.length(); i++) {  
                String[] pins = PinyinHelper.toHanyuPinyinStringArray(str.charAt(i), outputFormat);
                if(pins != null && pins[0].length() > 0) {
                	abbr.append(pins[0].charAt(0));
                }
            }  
        } catch (BadHanyuPinyinOutputFormatCombination e) {  
            e.printStackTrace();  
        }  
		return abbr.toString();
	}
	
	
}
